package com.stu.day17;

/**
 * @author zy
 * @date 2025/2/18 11:07
 */
public class JoinDemo {
    public static void main(String[] args) {
        Thread thread = new Thread(new PersonOne());
        thread.start();
    }
}

class PersonOne implements Runnable{
    @Override
    public void run() {
        System.out.println("甲拿起手机");
        System.out.println("甲给乙打电话");
        Thread thread = new Thread(new PersonTwo());
        thread.start();
        try {
            thread.join();  // 让外部线程进入堵塞状态
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        System.out.println("甲说:是我");
    }
}

class PersonTwo implements Runnable{
    @Override
    public void run() {
        System.out.println("乙接听电话");
        try {
            Thread.sleep(500);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        System.out.println("乙说:喂");
    }
}